/*
 * Copyright (C) 2012-2015 Apple Inc. All rights reserved.
 *
 * This document is the property of Apple Inc.
 * It is considered confidential and proprietary.
 *
 * This document may not be reproduced or transmitted in any form,
 * in whole or in part, without the express written permission of
 * Apple Inc.
 */
#ifndef __PLATFORM_SOC_HWCLOCKS_H
#define __PLATFORM_SOC_HWCLOCKS_H

#include <platform.h>
#include <platform/clocks.h>
#include SUB_PLATFORM_SPDS_HEADER(pmgr)

#if SUPPORT_FPGA
#define OSC_FREQ	(5000000UL)
#define LPO_FREQ	(OSC_FREQ)
#else
#define OSC_FREQ	(24000000UL)
#define LPO_FREQ	(192000000UL)
#endif

#if SUB_PLATFORM_S8000 || SUB_PLATFORM_S8003
/* 
 * S8000 clock gate devices.
 */
enum {
	// Mini-PMGR
	CLK_AOP = HWCLOCK_BASE,
	CLK_DEBUG,
	CLK_AOP_GPIO,
	CLK_AOP_UART0,
	CLK_AOP_UART1,
	CLK_AOP_UART2,
	CLK_AOP_I2CM,
	CLK_AOP_MCA0,
	CLK_AOP_CPU,
	CLK_AOP_FILTER,
	CLK_AOP_BUSIF,
	
	// PMGR
	CLK_SBR,
	CLK_AIC,
	CLK_DWI,
	CLK_GPIO,
	CLK_PMS,
	CLK_HSIC0PHY,
	CLK_HSIC1PHY,
	CLK_ISPSENS0,
	CLK_ISPSENS1,
	CLK_PCIE_REF,
	CLK_SIO_BUSIF,
	CLK_SIO_P,
	CLK_SIO,
	CLK_MCA0,
	CLK_MCA1,
	CLK_MCA2,
	CLK_MCA3,
	CLK_MCA4,
	CLK_PWM0,
	CLK_I2C0,
	CLK_I2C1,
	CLK_I2C2,
	CLK_I2C3,
	CLK_SPI0,
	CLK_SPI1,
	CLK_SPI2,
	CLK_SPI3,
	CLK_UART0,
	CLK_UART1,
	CLK_UART2,
	CLK_UART3,
	CLK_UART4,
	CLK_UART5,
	CLK_UART6,
	CLK_UART7,
	CLK_UART8,
	CLK_AES0,
	CLK_MCC,
	CLK_DCS0,
	CLK_DCS1,
	CLK_D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_I2C0,
	CLK_I2C1,
	CLK_I2C2,
	CLK_I2C3,
	CLK_SPI0,
	CLK_SPI1,
	CLK_SPI2,
	CLK_SPI3,
	CLK_UART0,
	CLK_UART1,
	CLK_UART2,
	CLK_UART3,
	CLK_UART4,
	CLK_UART5,
	CLK_UART6,
	CLK_UART7,
	CLK_UART8,
	CLK_AES0,
	CLK_DPA0,
	CLK_DPA1,
	CLK_MCC,
	CLK_DCS0,
	CLK_DCS1,
	CLK_DCS2,
	CLK_DCS3,
	CLK_DCS4,
	CLK_DCS5,
	CLK_DCS6,
	CLK_DCS7,
	CLK_USB,
	CLK_USBCTLREG,
	CLK_USB2HOST0,
	CLK_USB2HOST0_OHCI,
	CLK_USB2HOST1,
	CLK_USB2HOST1_OHCI,
	CLK_USB2HOST2,
	CLK_USB2HOST2_OHCI,
	CLK_USB_OTG,
	CLK_SMX,
	CLK_SF,
	CLK_RTMUX,
	CLK_DISP0,
	CLK_DP0,
	CLK_EDPLINK = CLK_DP0,
	CLK_DPLINK = CLK_DP0,
	CLK_DISP1MUX,
	CLK_DISP1,
	CLK_DP1,
	CLK_ISP,
	CLK_MEDIA,
	CLK_JPG,
	CLK_MSR,
	CLK_PMP,
	CLK_PMS_SRAM,
	CLK_VDEC0,
	CLK_VENC_CPU,
	CLK_PCIE,
	CLK_PCIE_AUX,
	CLK_PCIE_LINK0,
	CLK_PCIE_LINK1,
	CLK_PCIE_LINK2,
	CLK_PCIE_LINK3,
	CLK_PCIE_LINK4,
	CLK_PCIE_LINK5,
	CLK_GFX,
	CLK_SRS,

	// Unmanaged
	CLK_CPU0,
	CLK_CPU1,
	CLK_CPM,
	CLK_SEP,
	CLK_VENC_PIPE,
	CLK_VENC_ME0,
	CLK_VENC_ME1,

	CLK_LAST,
};
#endif

#define PMGR_DEVICE_INDEX(_clk) ((_clk) - HWCLOCK_BASE)
#define PMGR_DEVICE_COUNT (CLK_LAST - HWCLOCK_BASE)

#define PMGR_FIRST_DEVICE CLK_AOP
#if SUB_PLATFORM_S8000 || SUB_PLATFORM_S8003
#define PMGR_LAST_DEVICE CLK_GFX
#elif SUB_PLATFORM_S8001
#define PMGR_LAST_DEVICE CLK_SRS
#else
#error Unknown Platform
#endif

#define PMGR_VALID_DEVICE(_clk) ((_clk) >= PMGR_FIRST_DEVICE && (_clk) <= PMGR_LAST_DEVICE)

// Legacy clocks, no associated device or PS register
enum {
	CLK_FCLK = CLK_LAST,
	CLK_ACLK,
	CLK_HCLK,
	CLK_PCLK,
	CLK_VCLK0,
	CLK_VCLK1,
	CLK_MCLK,
	CLK_NCLK,
	CLK_USBPHYCLK,
	CLK_NCOREF,
};

#endif /* ! __PLATFORM_SOC_HWCLOCKS_H */
